﻿using System;
using System.Collections.Generic;
using System.IO.Ports;
using System.Text;

namespace KZ400B
{
    public class SPort
    {
        private int m_ID;

        public int ID
        {
            get { return m_ID; }
            set { m_ID = value; }
        }
        private string m_PortName;

        public string PortName
        {
            get { return m_PortName; }
            set { m_PortName = value; }
        }
        private int m_BaudRate;

        public int BaudRate
        {
            get { return m_BaudRate; }
            set { m_BaudRate = value; }
        }
        private Parity m_Parity;

        public Parity Parity
        {
            get { return m_Parity; }
            set { m_Parity = value; }
        }
        private int m_DataBits;

        public int DataBits
        {
            get { return m_DataBits; }
            set { m_DataBits = value; }
        }
        private StopBits m_StopBits;

        public StopBits StopBits
        {
            get { return m_StopBits; }
            set { m_StopBits = value; }
        }

        private CommEncoding m_Encoding;

        public CommEncoding Encoding
        {
            get { return m_Encoding; }
            set { m_Encoding = value; }
        }

        public static Encoding getPortEncoding(CommEncoding encoding)
        {
            Encoding ec = null;
            switch (encoding)
            { 
                case CommEncoding.ASCII:
                    ec = System.Text.Encoding.ASCII;
                    break;
                default:
                    ec = System.Text.Encoding.Default;
                    break;
            }
            return ec;
        }

        public SPort()
        {
            m_ID = 0;
            m_PortName = string.Empty;
            m_BaudRate = 9600;
            m_Parity = System.IO.Ports.Parity.None;
            m_DataBits = 8;
            m_StopBits = StopBits.One;
            m_Encoding = CommEncoding.ASCII;
        }
    }
}
